package com.lagou.blog.service;

import com.lagou.blog.mapper.ArticleMapper;
import com.lagou.blog.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    public Map<String, Object> getArticle(Integer page) {
        Map<String,Object> map = new HashMap<>();
        Integer num = 3;
        Integer count = articleMapper.acountAll();
        Integer pageNum = count/num;
        map.put("fisrt",0);
        map.put("pre",page==0?0:(page-1));
        map.put("page",page+1);
        map.put("next",page==pageNum?pageNum:page+1);
        map.put("last",pageNum);
        Integer start = page*num;
        List<Article> articles = articleMapper.selectLimit(start, 3);
        map.put("list",articles);
        return map;
    }
}
